package com.fastshopping.model.service.impl;

import com.fastshopping.model.dao.ShareMapper;
import com.fastshopping.model.service.ShareService;
import com.fastshopping.order.pojo.Share;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Name: 李袁勇
 * @Date: 2020/6/6 10:11
 * @Version: 1.0
 **/

@Service
public class ShareServiceImpl implements ShareService {

    @Autowired
    private ShareMapper shareMapper;
    @Override
    public List<Share> findAllShare(int user_id) {
        return shareMapper.findAllShare(user_id);
    }

    @Override
    public List <Share> findByState(int user_id, int state) {
        return shareMapper.findByState(user_id,state);
    }

    @Override
    public void addShare(Share share) {
        shareMapper.addState(share);
    }

    @Override
    public void addModel(int model_id) throws Exception {
        Share share = shareMapper.setShare(model_id);
        if(share != null ){
            shareMapper.addModel(share);
            shareMapper.updateState(model_id);
        }else{
            throw new Exception("没有数据哦");
        }
    }

    @Override
    public void theShelves(int model_id) {
        //先删除
        shareMapper.deleteModel(model_id);
        //在修改
        shareMapper.theShelves(model_id);
    }
}
